package com.yserp.project.erp.store.outorder.controller;

import com.yserp.common.exception.BusinessException;
import com.yserp.common.utils.StringUtils;
import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.store.outorder.domain.OutOrder;
import com.yserp.project.erp.store.outorder.domain.OutOrderItem;
import com.yserp.project.erp.store.outorder.domain.OutOrderItemVo;
import com.yserp.project.erp.store.outorder.service.IOutOrderItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 商品出库单子Controller
 * 
 * @author yserp
 * @date 2022-07-15
 */
@Controller
@RequestMapping("/store/outorder/item")
public class OutOrderItemController extends BaseController
{
    private String prefix = "store/outorder/item";

    @Autowired
    private IOutOrderItemService outOrderItemService;

    @RequiresPermissions("store:outorder:view")
    @GetMapping()
    public String outorder()
    {
        return prefix + "/outorder";
    }

    /**
     * 查询商品出库单子列表
     */
    @RequiresPermissions("store:outorder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OutOrderItem outOrderItem)
    {
        startPage();
        List<OutOrderItem> list = outOrderItemService.selectOutOrderItemList(outOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出商品出库单子列表
     */
    @RequiresPermissions("store:outorder:export")
    @Log(title = "商品出库单子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OutOrderItem outOrderItem)
    {
        List<OutOrderItem> list = outOrderItemService.selectOutOrderItemList(outOrderItem);
        ExcelUtil<OutOrderItem> util = new ExcelUtil<OutOrderItem>(OutOrderItem.class);
        return util.exportExcel(list, "商品出库单子数据");
    }

    /**
     * 通过仓库id,订单类型id,订单id获取出库单子表信息
     */
    @PostMapping("/ajaxList")
    @ResponseBody
    public AjaxResult ajaxList(OutOrder OutOrder) {
        Long sourceOrderId = OutOrder.getSourceOrderId();
        String orderType = OutOrder.getOrderType();
        Long warehouseId = OutOrder.getWarehouseId();

        if(null == sourceOrderId||null == warehouseId|| StringUtils.isBlank(orderType)){
            throw new BusinessException("参数为空");
        }
        List<OutOrderItemVo> outOrderItemVos = outOrderItemService.selectOutOrderItemListByParam(sourceOrderId, orderType, warehouseId);
        return AjaxResult.success(outOrderItemVos);
    }

}
